﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.Task;
using PowerCreator.LMS.Task.Entity;

public partial class sysadmin_TaskManager_ManagerTaskClassRoom : PowerCreator.LMS.Web.Base.BasePage
{
    TaskClassRoomManag objTaskClassRoomManag = new TaskClassRoomManag();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();
            string search = GetSearch();
            BinderPager(search);
            BinderPG(search, 1);
        }

    }

    protected override void InitPage()
    {
        lbl_InfoTitle_ManagerNew.Text = "管理教室";//GetLanageValueByKey("lab_ManagerNew_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_ManagerNew.Text = "新闻列表";
        btnAddNew.Text = GetLanageValueByKey("btn_AddNew", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnSearch.Text = GetLanageValueByKey("btn_Search", PowerCreator.LMS.Language.LanagetItemType.Page);

        chkAll.Text = GetLanageValueByKey("chkbox_ManagerQuestion_chkboxAll", PowerCreator.LMS.Language.LanagetItemType.Page);
        chkCancel.Text = GetLanageValueByKey("chkbox_ManagerQuestion_chkboxCancel", PowerCreator.LMS.Language.LanagetItemType.Page);

        btn_DelCheck.Text = GetLanageValueByKey("btnDel", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnAddNew.Text = GetLanageValueByKey("btn_AddNew", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_IsCheck.Text = GetLanageValueByKey("btnAuditing", PowerCreator.LMS.Language.LanagetItemType.Page);

        base.InitPage();

        //btnAddNew.Visible = false;
        //if (IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.AddJob))
        //    btnAddNew.Visible = true;

    }
    private string GetSearch()
    {
        string search = "";
        if (!string.IsNullOrEmpty(txtSearch.Text))
            search = string.Format("TaskCrName like '%{0}%'", txtSearch.Text.Trim());
        return search;
    }

    protected void BinderPager(string search)
    {
        AspNetPager1.RecordCount = objTaskClassRoomManag.Count(search);
        AspNetPager1.PageSize = LMSPageSize;
    }
    private void BinderPG(string search, int pageIndex)
    {
        string orderby = " TaskCrID desc";
        DataTable dt = objTaskClassRoomManag.Query(search, orderby, LMSPageSize, pageIndex);
        rptNew.DataSource = dt;
        rptNew.DataBind();

        PreAspNetPager(AspNetPager1);
    }
    protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {
            LinkButton lbtn = (LinkButton)e.Item.FindControl("lnkbtn_del");
            lbtn.Attributes.Add("onClick", "javascript:return confirm('确定删除此记录？');");
            Label lblTaskCrAuditState = (Label)e.Item.FindControl("lblTaskCrAuditState");
            if (lblTaskCrAuditState.Text == "0")
            {
                lblTaskCrAuditState.Text = "false";
            }
            else
            {
                lblTaskCrAuditState.Text = "ture";
            }
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderPG(search, 1);
    }
    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        string url = "AddTaskClassRoom.aspx";
        Script.RedirectURL(url);
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPG(search, AspNetPager1.CurrentPageIndex);
    }
    protected void rptNew_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        Label lbl_msg = (Label)e.Item.FindControl("lbl_msg");

        if (e.CommandName.ToLower() == "leditor")
        {
            if (IsLicensed("NewsUpdate"))
            {
                string url = "AddTaskClassRoom.aspx?ID=" + e.CommandArgument.ToString();
                Script.RedirectURL(url);
            }
            else
            {
                lbl_msg.Text = GetLanageValueByKey("msg_ManagerNew_checkmsg", PowerCreator.LMS.Language.LanagetItemType.Page);
            }
        }
        else if (e.CommandName.ToLower() == "ldel")
        {
            if (IsLicensed("NewsDel"))
            {
                if (objTaskClassRoomManag.Remove(int.Parse(e.CommandArgument.ToString())))
                {
                    string search = GetSearch();
                    BinderPager(search);
                    BinderPG(search, AspNetPager1.CurrentPageIndex);
                }
                else
                {
                    lbl_msg.Text = GetLanageValueByKey("Msg_ManagerQuestion_WorkNo", PowerCreator.LMS.Language.LanagetItemType.Page);
                }
            }
            else
            {
                lbl_msg.Text = GetLanageValueByKey("msg_ManagerNew_checkmsg", PowerCreator.LMS.Language.LanagetItemType.Page);
            }
        }
        else if (e.CommandName.ToLower() == "ischeck")
        {
            TaskClassRoom vo = new TaskClassRoom();
            vo = objTaskClassRoomManag.Load(int.Parse(e.CommandArgument.ToString()));
            if (vo.TaskCrAuditState == 0)
                vo.TaskCrAuditState = 1;
            //else
            //{
            //    vo.TaskCrAuditState = 0;
              
            //}
            objTaskClassRoomManag.Update(vo);
            string search = GetSearch();
            BinderPager(search);
            BinderPG(search, AspNetPager1.CurrentPageIndex);
        }
       

    }
    protected void chkAll_CheckedChanged(object sender, EventArgs e)
    {
        chkCancel.Checked = false;
        //全选 / 取消
        for (int i = 0; i < rptNew.Items.Count; i++)
        {
            CheckBox cbox = (CheckBox)rptNew.Items[i].FindControl("Chbox_Check");
            if (chkAll.Checked)
                cbox.Checked = true;
            else
                cbox.Checked = false;
        }
    }
    protected void chkCancel_CheckedChanged(object sender, EventArgs e)
    {
        chkAll.Checked = false;
        //反选
        for (int i = 0; i < rptNew.Items.Count; i++)
        {
            CheckBox cbox = (CheckBox)rptNew.Items[i].FindControl("Chbox_Check");
            if (cbox.Checked)
                cbox.Checked = false;
            else
                cbox.Checked = true;
        }
    }
    protected void btn_DelCheck_Click(object sender, EventArgs e)
    {
        try
        {
            for (int i = 0; i < rptNew.Items.Count; i++)
            {
                CheckBox cbox = (CheckBox)rptNew.Items[i].FindControl("Chbox_Check");
                Label lab_NewID = (Label)rptNew.Items[i].FindControl("lab_NewID");
                if (cbox.Checked)
                {
                    if (IsLicensed("NewsDel"))
                    {
                        if (objTaskClassRoomManag.Remove(int.Parse(lab_NewID.Text)))
                        {

                        }
                        else
                        {
                            Script.Alert(this, "msg", GetLanageValueByKey("Msg_ManagerQuestion_WorkNo", PowerCreator.LMS.Language.LanagetItemType.Page));
                        }
                    }
                    else
                    {
                        Script.Alert(this, "msg", GetLanageValueByKey("msg_ManagerNew_checkmsg", PowerCreator.LMS.Language.LanagetItemType.Page));
                    }
                }
            }
            string search = GetSearch();
            BinderPager(search);
            BinderPG(search, AspNetPager1.CurrentPageIndex);
            Script.Alert(this, "msg", GetLanageValueByKey("Msg_ManagerQuestion_WorkOK", PowerCreator.LMS.Language.LanagetItemType.Page));
        }
        catch
        {
            Script.Alert(this, "msg", GetLanageValueByKey("Msg_ManagerQuestion_WorkNo", PowerCreator.LMS.Language.LanagetItemType.Page));
        }
    }
    protected void btn_IsCheck_Click(object sender, EventArgs e)
    {
        try
        {
            for (int i = 0; i < rptNew.Items.Count; i++)
            {
                CheckBox cbox = (CheckBox)rptNew.Items[i].FindControl("Chbox_Check");
                Label lab_NewID = (Label)rptNew.Items[i].FindControl("lab_NewID");
                if (cbox.Checked)
                {
                    TaskClassRoom vo = new TaskClassRoom();
                    vo = objTaskClassRoomManag.Load(int.Parse(lab_NewID.Text));
                    if (vo.TaskCrAuditState == 0)
                        vo.TaskCrAuditState = 1;
                    //else
                    //{
                    //    vo.TaskCrAuditState = 0;
                        
                    //}
                    objTaskClassRoomManag.Update(vo);

                }
            }
            string search = GetSearch();
            BinderPager(search);
            BinderPG(search, AspNetPager1.CurrentPageIndex);
            Script.Alert(this, "msg", GetLanageValueByKey("Msg_ManagerQuestion_WorkOK", PowerCreator.LMS.Language.LanagetItemType.Page));
        }
        catch
        {
            Script.Alert(this, "msg", GetLanageValueByKey("Msg_ManagerQuestion_WorkNo", PowerCreator.LMS.Language.LanagetItemType.Page));
        }
    }
}
